Topic : Implement lexical analyzer to input 'C' program file and 
        a) Count number of comment line
        b) Eliminate Comment and
        c) Store output in another file


Code-

%{

   #include<stdio.h>
    int countcmt=0;
	int wt=0;
%}

%%
"/*"[^\n]*"*/" {countcmt++;}
"/*"[^\n]*\n   {countcmt++;}
[^\n]*"*/"
"//"[^\n]*      {countcmt++;}
"\t"
"[^ \n]*"
"[\t]+"       {wt++;}
%%

int main()
{
yyin=fopen("a.c", "r");
yyout=fopen("b.c", "w");
yylex();
printf("Number of comments=%d\n",countcmt);
return 0;
}


Input-
#include<stdio.h>

void main()
{
	int a,b;
	printf("enter the 1st number:");
	scanf("%d",&a);//accept first number
	printf("enter the 2nd number:");
	scanf("%d",&b);
	c=a+b/*add two numbers 
	print output*/ 
	printf("%d",c);
	
}

output-
#include<stdio.h>

void main()
{
int a,b;
printf("enter the 1st number:");
scanf("%d",&a);
printf("enter the 2nd number:");
scanf("%d",&b);
c=a+b 
printf("%d",c);

}


sakshi@ubuntu:~$ lex l2.l
sakshi@ubuntu:~$ cc lex.yy.c -ll
sakshi@ubuntu:~$ ./a.out
Number of comments=2